package com.xxxx.service.impl;

import com.xxxx.dao.BookDao;
import com.xxxx.pojo.Book;
import com.xxxx.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created By ShaoXikai on 2022/7/22
 */
@Service
public class BookServiceImpl implements BookService {

    @Autowired
    private BookDao bookDao;

    public boolean save(Book book) {
        return bookDao.save(book) > 0;
    }

    public boolean update(Book book) {
        return bookDao.update(book) > 0;
    }

    public boolean delete(Integer id) {
        return bookDao.delete(id) > 0;
    }

    public Book getById(Integer id) {
        // if(id == 1){
        //     throw new BusinessException(Code.BUSINESS_ERR,"请不要使用你的技术挑战我的耐性!");
        // }
        // try{
        //     int i = 1/0;
        // }catch (Exception e){
        //     throw new SystemException(Code.SYSTEM_TIMEOUT_ERR,"服务器访问超时，请重试!",e);
        // }
        return bookDao.getById(id);
    }

    public List<Book> getAll() {
        return bookDao.getAll();
    }

    @Override
    public List<Book> getByName(String name) {
        return bookDao.getByName(name);
    }
}
